package com.onpositive.dataminer.test;

import java.lang.reflect.Modifier;

import com.onpositive.knowledge.model.IThing;
import com.onpositive.knowledge.model.IType;
import com.onpositive.semantic.model.api.property.IProperty;
import com.onpositive.semantic.model.api.realm.IRealm;
import com.onpositive.semantic.model.api.realm.Realm;
import com.onpositive.semantic.model.ui.generic.IKnowsImageObject;
import com.onpositive.semantic.model.ui.generic.widgets.IHasImage;

public class ClassThing implements IThing, IType, IKnowsImageObject {

	Class<?> cl;

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((cl == null) ? 0 : cl.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ClassThing other = (ClassThing) obj;
		if (cl == null) {
			if (other.cl != null)
				return false;
		} else if (!cl.equals(other.cl))
			return false;
		return true;
	}

	public ClassThing(Class<?> superclass) {
		this.cl = superclass;
		
		Class<?>[] interfaces = cl.getInterfaces();
		for (Class c : interfaces) {
			realm.add(new ClassThing(c));
		}
		if (cl.getSuperclass()!=null){
		realm.add(new ClassThing(cl.getSuperclass()));
		}
	}

	@Override
	public String getId() {
		return cl.getName();
	}

	static final Realm TYPES = new Realm<IType>();
	static {
		TYPES.add(new ClassThing(Class.class));
	}

	@Override
	public IRealm<IType> getTypes() {
		return getSuperTypes();
	}

	protected Realm realm = new Realm();
	

	@Override
	public IRealm<IType> getSuperTypes() {

		return realm;
	}

	@Override
	public String toString() {
		return getId();
	}

	@Override
	public String getImageID() {
		if (Modifier.isInterface(cl.getModifiers())) {
			return "com.onpositive.dataminer.test.int";
		}
		return "com.onpositive.dataminer.test.class";

	}

	@Override
	public boolean isDepricated() {
		return false;
	}

	@Override
	public IProperty getProprty(String id) {
		return null;
	}

	@Override
	public Object getLongDefaultImage() {
		// TODO Auto-generated method stub
		return null;
	}
}
